Laboratory 2
CSSE 432 - Computer Networks

Due: Monday, March 19, 2012 by 11:55 PM

Purpose

Learn simple client/server programming in C.

Instructions

  1. Checkout the project Lab02 from your svn repository (svn update should do the trick if you checked out your entire repository in Lab01). Write your solutions to the problem below in that folder.

  2. Write a client-side C program that communicates with a simple server. The server program is provided as a binary file that will run on the Linux environment. Your client program should repeatedly:

    Communication between the client and the server should be in terms of packets with the following format:

    typedef struct {
      packettype  control;         /* type of packet */
      int         sequence;        /* packet's sequence number */
      int         loadsize;        /* amount of data (in bytes) */
      char        data[LOADSIZE];  /* holds data */
      int         checksum;        /* for error detection */
    } PACKET;
    
    
    typedef enum
      {ACK, DATA, ECHO, GET, PUT, RETR}
      packettype;
    
    
    #define LOADSIZE 30      /* Size of data area */
    

    When sending and receiving you need only use the control, loadsize, and data fields of the packets. The packets you send and the packets you receive should have packettype ECHO.

  3. The server program "server" and the helper files globals.c, globals.h, a Makefile and a template for the client, template.c have been added to folder Lab02 in your repository. The header file "globals.h" contains the PACKET type definition and some other useful functions. The template.c file is a starting point for your client program. Rename it client.c and modify it as per the specifications for this lab.

  4. Use the provided Makefile to build your client program. You may edit it as is necessary.

  5. Compile and run the programs on the Linux platform.

  6. Use the GNU C coding standards when your writing your C programs. The standards are available at http://www.gnu.org/prep/standards/standards.html#Writing-C. Sections to look at are "Comments", "Formatting", "Syntatic Conventions", and "Names".

  7. In your Makefile include a comment at the top with your name.

  8. Submit the source files (.c), the header files (.h) and the Makefile to your svn repository.

More Information

The server file is a binary file compiled on a Linux workstation. To use it:

  1. Checkout the folder called SERVER in your Lab02 folder.
  2. Change the mode of the file to executable, by typing the following at the Linux prompt:

     $ chmod 755 server
    
  3. Execute it with no options, -v for verbose, or -V for very verbose.

  4. You can also specify a different port to use:

     $ ./server -p 2222
    

    to use port 2222, for example. Port numbers must be bigger than 1023.

For the client:

  1. Use the provided file template.c to begin your client program. Rename it to client.c before submitting.

To run your client program with this server program: 1. Run server from the SERVER folder. 2. Run client from the Lab02 folder. Specify the IP address of the host machine that is running the server program and the port number as command line inputs. To determine the IP address of your Linux host, type ifconfig at the Linux prompt. e.g. ./client -h 192.168.1.103 -p 2222

Functions of interest: socket, recvfrom, sendto

The following website has a good description for how sockets work and what C functions are available: http://www.gnu.org/software/libc/manual/html_node/Sockets.html